import {
    editView
} from './views/edit.view';

import {validate} from './validate';
import {submit} from './submit';
import {
    msg, modal5
} from '../common/layer';
const editBtnHandler = () => {

    let selected = $('#table').bootstrapTable('getSelections');

    if (selected.length === 0) {
        msg('请选择一项编辑');
        return;
    }
    modal5('编辑', editView(selected));

    $(".modal-form input").iCheck({
        radioClass: 'iradio_minimal-blue'
    });

    $('#submitBtn').click(() => {
        let data = {};
        $.each($('#form').serializeArray(), (key, val) => {
            data[val.name] = $.trim(val.value);
        });

        if (!validate(data)) {
            return;
        }
        submit(GLOBAL_editUrl, data);
    });

};

export {editBtnHandler}
